package com.cskaoyan.service.admin.dashboard.impl;

import com.cskaoyan.bean.MarketGoodsExample;
import com.cskaoyan.bean.MarketGoodsProductExample;
import com.cskaoyan.bean.MarketOrderExample;
import com.cskaoyan.bean.MarketUserExample;
import com.cskaoyan.bean.vo.admin.dashboard.DashBoardVo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.service.admin.dashboard.DashBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author MoJunXiang
 * @since 2022/09/06 21:00
 */
@Service
public class DashBoardServiceImpl implements DashBoardService {

    @Autowired
    MarketGoodsMapper marketGoodsMapper;
    @Autowired
    MarketUserMapper marketUserMapper;
    @Autowired
    MarketGoodsProductMapper marketGoodsProductMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;


    /**
     * @function_name dashboard
     * @idea 返回 ***所有***  **用户数量** ， **商品数量** ， **货品数量** ， **订单数量**
     * @return com.cskaoyan.bean.common.BaseRespVo<com.cskaoyan.bean.vo.admin.dashboard.DashBoardVo>
     * @author MoJunXiang
     * @since 2022/09/08 11:49
     */
    @Override
    public BaseRespVo<DashBoardVo> dashboard() {
        int goodsTotal = ((int) marketGoodsMapper.countByExample(new MarketGoodsExample()));
        int userTotal = ((int) marketUserMapper.countByExample(new MarketUserExample()));
        int productTotal = (int) marketGoodsProductMapper.countByExample(new MarketGoodsProductExample());
        int orderTotal = (int) marketOrderMapper.countByExample(new MarketOrderExample());

        DashBoardVo dashBoardVo = new DashBoardVo(goodsTotal, userTotal, productTotal, orderTotal);

        return BaseRespVo.ok(dashBoardVo);
    }
}
